﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace TotalApplication.Core
{
    public partial class SettingMenuViewModel : BaseViewModel
    {
        #region Public Properties

        /// <summary>
        /// The current user's name
        /// </summary>
        [ObservableProperty]
        public TextEntryViewModel? _name;

        /// <summary>
        /// The current user's username
        /// </summary>
        [ObservableProperty]
        public TextEntryViewModel? _username;

        /// <summary>
        /// The current user's password
        /// </summary>
        [ObservableProperty]
        public PasswordEntryViewModel? _password;

        /// <summary>
        /// The current user's email
        /// </summary>
        [ObservableProperty]
        public TextEntryViewModel? _email;

        #endregion

        #region Constructor

        /// <summary>
        /// Default constructor
        /// </summary>
        public SettingMenuViewModel()
        {
            
        }

        #endregion

        #region Commands

        /// <summary>
        /// Closes the setting menu
        /// </summary>
        [RelayCommand]
        private void Back()
        {
            IoC.Application.SettingMenuVisible = false;
        }

        /// <summary>
        /// Opens the setting menu
        /// </summary>
        [RelayCommand]
        private void Open()
        {
            IoC.Application.SettingMenuVisible = true;
        }

        /// <summary>
        /// Logs the current user out
        /// </summary>
        [RelayCommand]
        private void Logout()
        {
            // TODO: Confirm the user wants to log out

            // TODO: Clear any user data/caches

            // Clear all application level view models that contain
            // any information about the current user
            ClearUserData();

            // Go back to login page
            IoC.Application.GoToPage(ApplicationPage.Login);
        }

        [RelayCommand]
        private void ClearUserData()
        {
            Name = null;
            Username = null;
            Password = null;
            Email = null;
        }
            #endregion
        }
}
